package com.service.admin.support;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

@Slf4j
@Component
public class MemberMerchantLockUtils extends RedissonLockUtils {

    public boolean lockCreateMerchant(@NotNull Integer memberId) {
        return super.lock(buildCreateMerchantLock(memberId));
    }

    public void unlockCreateMerchant(@NotNull Integer memberId) {
        super.unlock(buildCreateMerchantLock(memberId));
    }


    public static String buildCreateMerchantLock(Integer memberId){
        return RedisLockConstant.MEMBER_MERCHANT+memberId;
    }

    public boolean lockCreditLine(@NotNull Integer merchantId, @NotNull String coinName){
        return super.lock(buildCreditLineLockKey(merchantId, coinName));
    }

    public void unlockCreditLine(@NotNull Integer merchantId, @NotNull String coinName) {
        super.unlock(buildCreditLineLockKey(merchantId, coinName));
    }

    public static String buildCreditLineLockKey(Integer merchantId, String coinName){
        return RedisLockConstant.MEMBER_MERCHANT_CREDIT_LINE + merchantId + RedisLockConstant.INTERVAL + coinName;
    }


}
